package com.healthchart.app.activity;

import android.os.Bundle;
import com.healthchart.app.R;
import com.healthchart.app.adapter.MyFragmentPagerAdapter;
import com.healthchart.app.controlview.ScrollPickerView;
import com.healthchart.app.controlview.StringScrollPicker;
import com.healthchart.app.controlview.ViewPagerSlide;
import com.healthchart.app.fragment.BodyFragment;
import com.healthchart.app.fragment.TotalFragment;
import java.util.ArrayList;
import java.util.List;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

public class MainActivity extends FragmentActivity  {

    private String tag = "MainActivity";
    private int mIndex = 0;
    private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
    private ViewPagerSlide viewPager;
    private StringScrollPicker mPickerHorizontal;
    private String[] strs = {"总览","体重","体脂率","水分","体质年龄","内脏等级","体重控制","脂肪控制","bml","bmr"};

    TotalFragment of1 = null;
    BodyFragment of2 = null;
    BodyFragment of3 = null;
    BodyFragment of4 = null;
    BodyFragment of5 = null;
    BodyFragment of6 = null;
    BodyFragment of7 = null;
    BodyFragment of8 = null;
    BodyFragment of9 = null;
    BodyFragment of10 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = findViewById(R.id.viewpage);

        of1 = new TotalFragment();
        mFragments.add(of1);
        of2 = new BodyFragment();
        mFragments.add(of2);
        of3 = new BodyFragment();
        mFragments.add(of3);
        of4 = new BodyFragment();
        mFragments.add(of4);
        of5 = new BodyFragment();
        mFragments.add(of5);
        of6 = new BodyFragment();
        mFragments.add(of6);
        of7 = new BodyFragment();
        mFragments.add(of7);
        of8 = new BodyFragment();
        mFragments.add(of8);
        of9 = new BodyFragment();
        mFragments.add(of9);
        of10 = new BodyFragment();
        mFragments.add(of10);
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragments));
        viewPager.setCurrentItem(mIndex);
        viewPager.setOffscreenPageLimit(9);

        mPickerHorizontal = (StringScrollPicker) findViewById(R.id.picker_horizontal);
        List<String> newList = new ArrayList<String>();
        for (int i = 0; i <strs.length ; i++) {
            newList.add(strs[i]);
        }
        mPickerHorizontal.setData(newList);
        mPickerHorizontal.setSelectedPosition(0);
        mPickerHorizontal.setOnSelectedListener(new ScrollPickerView.OnSelectedListener() {
            @Override
            public void onSelected(ScrollPickerView scrollPickerView, int position) {
                viewPager.setCurrentItem(position);
            }
        });
    }
}
